﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class TownshipEnterprise_PartChart : System.Web.UI.Page
{
    static string deptid = string.Empty;
    static string flag = string.Empty;

    public String SumSy = "";
    public String Sumqsy = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {

            deptid = Request.QueryString["DepartmentID"].ToString();
            flag = Request.QueryString["Flag"].ToString();

            if (deptid == null || flag == null)
            {
                Response.Write("<script language=javascript>alert('参数获取错误1')</script>");
                return;
            }
            else
            {
                //
                BindChar();
            }
        }
        catch
        {
            Response.Write("<script language=javascript>alert('参数获取错误!')</script>");
            return;
        }
    }
    private bool BindChar()
    {
        if (deptid.Length == 7)
        {
            deptid = deptid.Substring(0, 4);
        }
        else
        {
            Response.Write("<script language=javascript>alert('参数获取错误!')</script>");
            return false;
        }


        UserChart.Titles["Title"].Text = "专职消防队统计图";
        UserChart.ChartAreas["Default"].AxisX.LabelsAutoFit = false;

        DBCls db = new DBCls();
        DataTable dt = db.QueryDataTable("select a.he AS sy,vtcaq.he AS qsy FROM View_TownbasicCharArtSY a,View_TownbasicCharArtQSY vtcaq WHERE a.DepartmentID=vtcaq.DepartmentID AND a.DepartmentID like '" + deptid + "%'", "sum");

        if (dt.Rows.Count > 0)
        {
            SumSy = dt.Rows[0]["sy"].ToString();
            Sumqsy = dt.Rows[0]["qsy"].ToString();
        }
        if (flag == "1")
        {
            //企事业专职消防队
            string sqlqsy = "select a.DepartmentID,count(a.DepartmentID) as he ,b.shortname from Townbasic a left join Account_Departments b on a.DepartmentID=b.DepartmentID where a.FBType='企事业专职消防队' and a.departmentid like '" + deptid + "%' group by a.DepartmentID,b.shortname";
            DataView dvqsy = db.QueryDataView(sqlqsy, "qsy");


            UserChart.Series["企事业消防队"].Points.DataBindXY(dvqsy, "shortname", dvqsy, "he");

            for (int i = 0; i < dvqsy.Count; i++)
            {
                UserChart.Series["企事业消防队"].Points[i].Href = "AllList.aspx?DepartmentID=" + dvqsy[i][0].ToString() + "&Flag=1";
            }
        }
        else
        {
            //乡镇四有消防队
            string sqlsy = "select a.DepartmentID,count(a.DepartmentID) as he ,REPLACE (b.shortname,'消防大队','') as shortname from Townbasic a left join Account_Departments b on a.DepartmentID=b.DepartmentID where a.FBType='乡镇四有消防队' and a.departmentid like '" + deptid + "%' group by a.DepartmentID,b.shortname";
            DataView dvsy = db.QueryDataView(sqlsy, "sy");
            UserChart.Series["乡镇四有消防队"].Points.DataBindXY(dvsy, "shortname", dvsy, "he");

            for (int i = 0; i < dvsy.Count; i++)
            {
                UserChart.Series["乡镇四有消防队"].Points[i].Href = "AllList.aspx?DepartmentID=" + dvsy[i][0].ToString() + "&Flag=2";
            }
        }
        UserChart.Series["乡镇四有消防队"].Name = "乡镇四有消防队 总计：" + SumSy;
        UserChart.Series["企事业消防队"].Name = "企事业消防队 总计：" + Sumqsy;
        return true;
    }
}
